package com.tools.payhelper;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.tools.payhelper.utils.AbSharedUtil;
import com.tools.payhelper.utils.LogUtil;
import com.tools.payhelper.utils.PayHelperUtils;

/**
 * @author SuXiaoliang
 * @ClassName: AlarmReceiver
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2018年6月23日 下午1:25:47
 */

public class AlarmReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            long currentTimeMillis = System.currentTimeMillis() / 1000;
            String time = AbSharedUtil.getString(context, "time");
            if(TextUtils.isEmpty(time)){
                time = "0";
            }
            long currentTimeMillis2 = Long.parseLong(time);
            long currentTimeMillis3 = currentTimeMillis - currentTimeMillis2;

            LogUtil.printLog(currentTimeMillis + "----" + currentTimeMillis2 + "-----" + currentTimeMillis3);

            if (currentTimeMillis3 > 60 && currentTimeMillis2 != 0) {
                PayHelperUtils.sendmsg(context, "轮询任务出现异常,重启中...");
                PayHelperUtils.startAlipayMonitor(context);
                PayHelperUtils.sendmsg(context, "轮询任务重启成功");
            }
        } catch (Exception e) {
            PayHelperUtils.sendmsg(context, "AlarmReceiver异常->>" + e.getMessage());
        }
    }

}
